package com.haoyang.sort;

import java.util.Arrays;

public class A02_SelectSortDemo2 {
    public static void main(String[] args) {
        int[] arr = {3, 2, 4, 5, 1};
        int[] sortedArr = selectSort(arr);
        System.out.println(Arrays.toString(sortedArr));
    }

    public static int[] selectSort(int[] arr) {
        // 外层循环控制次数.
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = j + 1; i < arr.length; i++) {
                if (arr[i] < arr[j]) {
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
}
